<?php
/**
* @author Bimal Poudel
* @copyright since 2006, Bimal Poudel
* @package Smarty Framework
* @support http://www.odesk.com/users/~~dd91d11caed0cdce
* @contact http://www.sanjaal.com
* @company Sanjaal Corps
*/

# Created on: 2011-03-26 02:03:36 285

/**
* Add an entity in [ categories ]
*/

$categories = new categories();

if($variable->post('add-action', 'string', ''))
{
	# Posted Data: Apply security
	$data = $variable->post('categories', 'array', array());
	
	# Immediately activate the record
	$data['is_active'] = 'Y';
	
	# When this record is added for the first time?
	$data['added_on'] = 'UNIX_TIMESTAMP(CURRENT_TIMESTAMP())';
	
	# Bind the data edited, to the current subdomain only, if there is a subdomain_id column
	$data['subdomain_id'] = framework::subdomain_id();

	if($category_id = $categories->add($data, false))
	{
		# Send a welcome message (and ask to authenticate)
		#$categories->welcome_first($category_id);

		$messenger = new messenger('success', 'The record has been added.');

		stopper::url(url::last_page('categories-list.php'));
		#stopper::url('categories-add-successful.php');
		#stopper::url('categories-list.php');
		
		# Once successfully added, as the admin user to edit the data.
		#stopper::url('categories-edit.php?id='.$category_id);
	}
	else
	{
		$messenger = new messenger('error', 'The record was NOT added.');

		stopper::url('categories-add-error.php');
	}
}
else
{
	# Must allow a chance to load the ADD form.
	# stopper::url('categories-direct-access-error.php');

	# Purpose of this code block is to make sure that the variable
	# gets all indices with blank data, to feed to ADD form.
	
	# A dynamic details about this record
	$details = array();

	# Validate it against the parameters in itself, plus those what we need.
	$details = $categories->validate('add', $details);
	$smarty->assign('categories', $details);
}

$smarty->assign('protection_code', $categories->code());
?>